using System;
using System.Data;
using System.IO;
using System.Xml;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;
using OracleInternal.ServiceObjects;

namespace Oracle.ManagedDataAccess.Types
{
	public sealed class OracleXmlType : ICloneable, IDisposable, INullable
	{
		internal OracleConnection m_connection;

		private bool m_bNotNull = true;

		private bool m_bClosed;

		private bool m_bPopluateSchema;

		private bool m_bIsSchemaBased;

		private bool m_bIsEmpty;

		private string m_schemaURL = string.Empty;

		private OracleClob m_schemaClob;

		private byte[] m_schemaID;

		private bool m_bGotRootElement;

		private string m_rootElement = string.Empty;

		private object lockXmlType = new object();

		internal OracleXmlTypeImpl m_xmlTypeImpl;

		internal OracleCommand m_command;

		public static readonly OracleXmlType Null = new OracleXmlType();

		public OracleConnection Connection
		{
			get
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					return null;
				}
				return m_connection;
			}
		}

		public bool IsEmpty
		{
			get
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				return m_bIsEmpty;
			}
		}

		public bool IsNull => !m_bNotNull;

		public bool IsSchemaBased
		{
			get
			{
				try
				{
					if (m_bClosed)
					{
						throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
					}
					if (!m_bNotNull)
					{
						throw new OracleNullValueException();
					}
					if (m_bIsEmpty)
					{
						m_bPopluateSchema = true;
						return m_bIsSchemaBased = false;
					}
					if (!m_xmlTypeImpl.m_bGotSchemaInfo)
					{
						m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
					}
					string xmlSchemaValue;
					return GetSchemaInfo(bGetSchemaValue: false, out xmlSchemaValue);
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.get_IsSchemaBased, ex);
					throw;
				}
			}
		}

		public bool IsFragment
		{
			get
			{
				try
				{
					if (m_bClosed)
					{
						throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
					}
					if (!m_bNotNull)
					{
						return false;
					}
					if (m_bIsEmpty)
					{
						return false;
					}
					if (m_xmlTypeImpl.m_bGotFragmentProp)
					{
						return m_xmlTypeImpl.m_bIsFragment;
					}
					m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
					return m_xmlTypeImpl.m_bIsFragment;
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.get_IsFragment, ex);
					throw;
				}
			}
		}

		public string RootElement
		{
			get
			{
				try
				{
					if (m_bClosed)
					{
						throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
					}
					if (!m_bNotNull)
					{
						throw new OracleNullValueException();
					}
					if (m_bGotRootElement)
					{
						return m_rootElement;
					}
					if (m_bIsEmpty)
					{
						m_bGotRootElement = true;
						return m_rootElement = string.Empty;
					}
					if (m_xmlTypeImpl.m_bIsFragment)
					{
						m_bGotRootElement = true;
						return m_rootElement = string.Empty;
					}
					XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
					m_rootElement = DotNetXmlImpl.GetRootElement(xmlDocument);
					m_bGotRootElement = true;
					return m_rootElement;
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.get_RootElement, ex);
					throw;
				}
			}
		}

		public OracleXmlType Schema
		{
			get
			{
				try
				{
					if (m_bClosed)
					{
						throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
					}
					if (!m_bNotNull)
					{
						throw new OracleNullValueException();
					}
					if (m_bIsEmpty)
					{
						m_bPopluateSchema = true;
						return new OracleXmlType(m_connection);
					}
					if (!m_xmlTypeImpl.m_bGotSchemaInfo)
					{
						m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
					}
					GetSchemaInfo(bGetSchemaValue: true, out var xmlSchemaValue);
					if (m_bIsSchemaBased && xmlSchemaValue != null)
					{
						return new OracleXmlType(m_connection, xmlSchemaValue);
					}
					return new OracleXmlType(m_connection);
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.get_Schema, ex);
					throw;
				}
			}
		}

		public string SchemaUrl
		{
			get
			{
				try
				{
					if (m_bClosed)
					{
						throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
					}
					if (!m_bNotNull)
					{
						throw new OracleNullValueException();
					}
					if (m_bIsEmpty)
					{
						m_bPopluateSchema = true;
						return string.Empty;
					}
					if (!m_xmlTypeImpl.m_bGotSchemaInfo)
					{
						m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
					}
					if (GetSchemaInfo(bGetSchemaValue: false, out var _))
					{
						return m_schemaURL;
					}
					return string.Empty;
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.get_SchemaUrl, ex);
					throw;
				}
			}
		}

		public string Value
		{
			get
			{
				try
				{
					if (m_bClosed)
					{
						throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
					}
					if (!m_bNotNull)
					{
						throw new OracleNullValueException();
					}
					return m_xmlTypeImpl.GetString();
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.get_Value, ex);
					throw;
				}
			}
		}

		~OracleXmlType()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.dtor);
			}
			try
			{
				try
				{
					Dispose(disposing: false);
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.dtor, ex);
				}
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.dtor);
				}
			}
		}

		public OracleXmlType(OracleConnection con, string xmlData)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(con, string)\n");
			}
			if (con == null)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentNullException("con", (string?)null);
			}
			if (ConnectionState.Open != con.m_connectionState)
			{
				GC.SuppressFinalize(this);
				throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_CLOSED));
			}
			if (xmlData == null)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentNullException("xmlData");
			}
			if (xmlData.Length == 0)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "xmlData"), "xmlData");
			}
			m_connection = con;
			m_xmlTypeImpl = new OracleXmlTypeImpl(m_connection.m_oracleConnectionImpl, TypeOfXmlType.String, TypeOfXmlData.String, xmlData);
			m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: true);
			if (m_connection.m_oracleConnectionImpl != null)
			{
				m_connection.m_oracleConnectionImpl.RegisterForConnectionClose(this);
			}
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(con, string)\n");
			}
		}

		public OracleXmlType(OracleClob clob)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(clob)\n");
			}
			if (clob == null)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentNullException("clob");
			}
			if (clob.m_connection == null)
			{
				GC.SuppressFinalize(this);
				throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "clob"));
			}
			if (ConnectionState.Open != clob.m_connection.m_connectionState)
			{
				GC.SuppressFinalize(this);
				throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_CLOSED));
			}
			m_connection = clob.Connection;
			if (clob.IsEmpty)
			{
				m_bIsEmpty = true;
			}
			m_xmlTypeImpl = new OracleXmlTypeImpl(m_connection.m_oracleConnectionImpl, TypeOfXmlType.Clob, TypeOfXmlData.Clob, clob);
			m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: true);
			if (m_connection.m_oracleConnectionImpl != null)
			{
				m_connection.m_oracleConnectionImpl.RegisterForConnectionClose(this);
			}
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(clob)\n");
			}
		}

		public OracleXmlType(OracleConnection con, XmlReader reader)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(con, xmlreader)\n");
			}
			if (con == null)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentNullException("con", (string?)null);
			}
			if (ConnectionState.Open != con.m_connectionState)
			{
				GC.SuppressFinalize(this);
				throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_CLOSED));
			}
			if (reader == null)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentNullException("reader");
			}
			string text = DotNetXmlImpl.ConvertXmlReaderToString(reader);
			if (string.IsNullOrEmpty(text))
			{
				GC.SuppressFinalize(this);
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "reader"), "reader");
			}
			m_connection = con;
			m_xmlTypeImpl = new OracleXmlTypeImpl(m_connection.m_oracleConnectionImpl, TypeOfXmlType.String, TypeOfXmlData.String, text);
			if (m_connection.m_oracleConnectionImpl != null)
			{
				m_connection.m_oracleConnectionImpl.RegisterForConnectionClose(this);
			}
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(con, xmlreader)\n");
			}
		}

		public OracleXmlType(OracleConnection con, XmlDocument domDoc)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(con, xmldocument)\n");
			}
			if (con == null)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentNullException("con");
			}
			if (ConnectionState.Open != con.m_connectionState)
			{
				GC.SuppressFinalize(this);
				throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_CLOSED));
			}
			if (domDoc == null)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentNullException("domDoc");
			}
			string text = DotNetXmlImpl.ConvertXmlDocToString(domDoc);
			if (string.IsNullOrEmpty(text))
			{
				GC.SuppressFinalize(this);
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "domDoc"), "domDoc");
			}
			m_connection = con;
			m_xmlTypeImpl = new OracleXmlTypeImpl(m_connection.m_oracleConnectionImpl, TypeOfXmlType.String, TypeOfXmlData.String, text);
			if (m_connection.m_oracleConnectionImpl != null)
			{
				m_connection.m_oracleConnectionImpl.RegisterForConnectionClose(this);
			}
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(con, xmldocument)\n");
			}
		}

		internal OracleXmlType(OracleConnection conn, OracleXmlTypeImpl xmlTypeImpl)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(conn, OracleXmlTypeImpl)\n");
			}
			m_connection = conn;
			m_xmlTypeImpl = xmlTypeImpl;
			m_xmlTypeImpl.Initialize(m_connection);
			if (m_xmlTypeImpl.IsEmptyXmlTypeData())
			{
				m_bIsEmpty = true;
			}
			if (m_connection.m_oracleConnectionImpl != null)
			{
				m_connection.m_oracleConnectionImpl.RegisterForConnectionClose(this);
			}
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (EXIT) OracleXmlType::OracleXmlType(conn, OracleXmlTypeImpl)\n");
			}
		}

		internal OracleXmlType(OracleConnection con)
			: this(con, new OracleXmlTypeImpl(con.m_oracleConnectionImpl, TypeOfXmlType.String, TypeOfXmlData.String, ""))
		{
		}

		internal OracleXmlType(OracleXmlType orgXmlType)
		{
			m_connection = orgXmlType.m_connection;
			m_xmlTypeImpl = orgXmlType.m_xmlTypeImpl.Clone();
			m_bPopluateSchema = orgXmlType.m_bPopluateSchema;
			if (m_bPopluateSchema)
			{
				m_bIsSchemaBased = orgXmlType.m_bIsSchemaBased;
				m_schemaURL = orgXmlType.m_schemaURL;
				m_schemaClob = orgXmlType.m_schemaClob;
			}
			m_bIsEmpty = orgXmlType.m_bIsEmpty;
			m_bGotRootElement = orgXmlType.m_bGotRootElement;
			if (m_bGotRootElement)
			{
				m_rootElement = orgXmlType.m_rootElement;
			}
			if (m_connection != null && m_connection.m_oracleConnectionImpl != null)
			{
				m_connection.m_oracleConnectionImpl.RegisterForConnectionClose(this);
			}
		}

		internal OracleXmlType(OracleConnection con, string xmlData, bool bThrowException)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(con, string)\n");
			}
			if (con == null)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentNullException("con", (string?)null);
			}
			if (ConnectionState.Open != con.m_connectionState)
			{
				GC.SuppressFinalize(this);
				throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_CLOSED));
			}
			if (xmlData == null)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentNullException("xmlData");
			}
			if (xmlData.Length == 0)
			{
				GC.SuppressFinalize(this);
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "xmlData"), "xmlData");
			}
			m_connection = con;
			m_xmlTypeImpl = new OracleXmlTypeImpl(m_connection.m_oracleConnectionImpl, TypeOfXmlType.String, TypeOfXmlData.String, xmlData);
			if (m_connection.m_oracleConnectionImpl != null)
			{
				m_connection.m_oracleConnectionImpl.RegisterForConnectionClose(this);
			}
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ctor, " (ENTRY) OracleXmlType::OracleXmlType(con, string)\n");
			}
		}

		private OracleXmlType()
		{
			m_bNotNull = false;
			m_bIsEmpty = true;
		}

		public void Dispose()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Dispose);
			}
			try
			{
				Dispose(disposing: true);
				GC.SuppressFinalize(this);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Dispose, ex);
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Dispose);
				}
			}
		}

		public object Clone()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Clone);
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					return Null;
				}
				return new OracleXmlType(this);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Clone, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Clone);
				}
			}
		}

		public OracleXmlType Extract(string xpathExpr, string nsMap)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Extract, "OracleXmlType::Extract(xpath, nsmap)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (string.IsNullOrEmpty(xpathExpr))
				{
					throw new ArgumentNullException("xpathExpr");
				}
				if (m_bIsEmpty)
				{
					return new OracleXmlType(m_connection);
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				string text = null;
				text = ((m_xmlTypeImpl.m_xmlDocFragmentInternal == null) ? DotNetXmlImpl.Extract(xmlDocument, xpathExpr, nsMap) : DotNetXmlImpl.Extract(xmlDocument, "/" + xpathExpr, nsMap));
				if (!string.IsNullOrEmpty(text))
				{
					OracleXmlType result = new OracleXmlType(m_connection, text, bThrowException: false)
					{
						m_xmlTypeImpl = 
						{
							m_bIsFragment = true,
							m_bGotFragmentProp = true
						},
						m_rootElement = string.Empty
					};
					m_bGotRootElement = true;
					return result;
				}
				return new OracleXmlType(m_connection);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Extract, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Extract, "OracleXmlType::Extract(xpath, nsmap)");
				}
			}
		}

		public OracleXmlType Extract(string xpathExpr, XmlNamespaceManager nsMgr)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Extract, "OracleXmlType::Extract(xpath, nsmgr)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (string.IsNullOrEmpty(xpathExpr))
				{
					throw new ArgumentNullException("xpathExpr");
				}
				if (m_bIsEmpty)
				{
					return new OracleXmlType(m_connection);
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				string text = null;
				text = ((m_xmlTypeImpl.m_xmlDocFragmentInternal == null) ? DotNetXmlImpl.Extract(xmlDocument, xpathExpr, nsMgr) : DotNetXmlImpl.Extract(xmlDocument, "/" + xpathExpr, nsMgr));
				if (!string.IsNullOrEmpty(text))
				{
					OracleXmlType result = new OracleXmlType(m_connection, text, bThrowException: false)
					{
						m_xmlTypeImpl = 
						{
							m_bIsFragment = true,
							m_bGotFragmentProp = true
						},
						m_rootElement = string.Empty
					};
					m_bGotRootElement = true;
					return result;
				}
				return new OracleXmlType(m_connection);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Extract, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Extract, "OracleXmlType::Extract(xpath, nsmgr)");
				}
			}
		}

		public OracleXmlStream GetStream()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetStream);
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				return new OracleXmlStream(this);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetStream, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetStream);
				}
			}
		}

		public XmlDocument GetXmlDocument()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetXmlDocument);
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bIsEmpty)
				{
					return new XmlDocument();
				}
				string value = Value;
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.PreserveWhitespace = true;
				XmlReader reader = XmlReader.Create(settings: new XmlReaderSettings
				{
					DtdProcessing = DtdProcessing.Ignore
				}, input: new StringReader(value));
				xmlDocument.Load(reader);
				return xmlDocument;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetXmlDocument, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetXmlDocument);
				}
			}
		}

		public XmlReader GetXmlReader()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetXmlReader);
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bIsEmpty)
				{
					return XmlReader.Create(new StringReader(""));
				}
				return new XmlTextReader(new StringReader(Value));
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetXmlReader, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetXmlReader);
				}
			}
		}

		public bool IsExists(string xpathExpr, string nsMap)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.IsExists, "OracleXmlType::IsExists(xpath, nsmap)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					return false;
				}
				if (string.IsNullOrEmpty(xpathExpr))
				{
					throw new ArgumentNullException("xpathExpr");
				}
				if (m_bIsEmpty)
				{
					return false;
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				if (m_xmlTypeImpl.m_xmlDocFragmentInternal != null)
				{
					return DotNetXmlImpl.IsExists(xmlDocument, "/" + xpathExpr, nsMap);
				}
				return DotNetXmlImpl.IsExists(xmlDocument, xpathExpr, nsMap);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.IsExists, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.IsExists, "OracleXmlType::IsExists(xpath, nsmap)");
				}
			}
		}

		public bool IsExists(string xpathExpr, XmlNamespaceManager nsMgr)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.IsExists, "OracleXmlType::IsExists(xpath, nsmgr)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					return false;
				}
				if (string.IsNullOrEmpty(xpathExpr))
				{
					throw new ArgumentNullException("xpathExpr", (string?)null);
				}
				if (m_bIsEmpty)
				{
					return false;
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				if (m_xmlTypeImpl.m_xmlDocFragmentInternal != null)
				{
					return DotNetXmlImpl.IsExists(xmlDocument, "/" + xpathExpr, nsMgr);
				}
				return DotNetXmlImpl.IsExists(xmlDocument, xpathExpr, nsMgr);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.IsExists, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.IsExists, "OracleXmlType::IsExists(xpath, nsmgr)");
				}
			}
		}

		public OracleXmlType Transform(OracleXmlType xsldoc, string paramMap)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Transform, "OracleXmlType::Transform(xmltypexsldoc, paramMap)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (xsldoc == null || xsldoc.IsNull)
				{
					throw new ArgumentNullException("xsldoc");
				}
				if (m_bIsEmpty)
				{
					return new OracleXmlType(m_connection);
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				string text = DotNetXmlImpl.Transform(xsldoc, xmlDocument, paramMap);
				if (!string.IsNullOrEmpty(text))
				{
					return new OracleXmlType(m_connection, text, bThrowException: false);
				}
				return new OracleXmlType(m_connection);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Transform, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Transform, "OracleXmlType::Transform(xmltypexsldoc, paramMap)");
				}
			}
		}

		public OracleXmlType Transform(string xsldoc, string paramMap)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Transform, "OracleXmlType::Transform(xsldoc, paramMap)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (string.IsNullOrEmpty(xsldoc))
				{
					throw new ArgumentNullException("xsldoc");
				}
				if (m_bIsEmpty)
				{
					return new OracleXmlType(m_connection);
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				string text = DotNetXmlImpl.Transform(xsldoc, xmlDocument, paramMap);
				if (!string.IsNullOrEmpty(text))
				{
					return new OracleXmlType(m_connection, text, bThrowException: false);
				}
				return new OracleXmlType(m_connection);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Transform, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Transform, "OracleXmlType::Transform(xsldoc, paramMap)");
				}
			}
		}

		public void Update(string xpathExpr, string nsMap, OracleXmlType val)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, "OracleXmlType::Update(xpathexpr, nsmap, xmltypeval)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (string.IsNullOrEmpty(xpathExpr))
				{
					throw new ArgumentNullException("xpathExpr");
				}
				if (val == null)
				{
					throw new ArgumentNullException("val");
				}
				if (string.IsNullOrEmpty(nsMap))
				{
					nsMap = null;
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				bool bOriginalFragmentValue;
				bool bValueIsFragment;
				if (m_xmlTypeImpl.m_xmlDocFragmentInternal != null)
				{
					bOriginalFragmentValue = (bValueIsFragment = true);
					DotNetXmlImpl.Update(xmlDocument, "/" + xpathExpr, nsMap, val.Value, ref bValueIsFragment);
				}
				else
				{
					bOriginalFragmentValue = (bValueIsFragment = false);
					DotNetXmlImpl.Update(xmlDocument, xpathExpr, nsMap, val.Value, ref bValueIsFragment);
				}
				m_xmlTypeImpl.Invalidate(bOriginalFragmentValue, bValueIsFragment, ref m_bGotRootElement);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, "OracleXmlType::Update(xpathexpr, nsmap, xmltypeval)");
				}
			}
		}

		public void Update(string xpathExpr, XmlNamespaceManager nsMgr, OracleXmlType val)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, "OracleXmlType::Update(xpathexpr, nsMgr, xmltypeval)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (string.IsNullOrEmpty(xpathExpr))
				{
					throw new ArgumentNullException("xpathExpr");
				}
				if (val == null)
				{
					throw new ArgumentNullException("val");
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				bool bOriginalFragmentValue;
				bool bValueIsFragment;
				if (m_xmlTypeImpl.m_xmlDocFragmentInternal != null)
				{
					bOriginalFragmentValue = (bValueIsFragment = true);
					DotNetXmlImpl.Update(xmlDocument, "/" + xpathExpr, nsMgr, val.Value, ref bValueIsFragment);
				}
				else
				{
					bOriginalFragmentValue = (bValueIsFragment = false);
					DotNetXmlImpl.Update(xmlDocument, xpathExpr, nsMgr, val.Value, ref bValueIsFragment);
				}
				m_xmlTypeImpl.Invalidate(bOriginalFragmentValue, bValueIsFragment, ref m_bGotRootElement);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, "OracleXmlType::Update(xpathexpr, nsMgr, xmltypeval)");
				}
			}
		}

		public void Update(string xpathExpr, string nsMap, string val)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, "OracleXmlType::Update(xpathexpr, nsmap, stringval)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (string.IsNullOrEmpty(xpathExpr))
				{
					throw new ArgumentNullException("xpathExpr");
				}
				if (val == null)
				{
					throw new ArgumentNullException("val");
				}
				if (string.IsNullOrEmpty(nsMap))
				{
					nsMap = null;
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				bool bOriginalFragmentValue;
				bool bValueIsFragment;
				if (m_xmlTypeImpl.m_xmlDocFragmentInternal != null)
				{
					bOriginalFragmentValue = (bValueIsFragment = true);
					DotNetXmlImpl.Update(xmlDocument, "/" + xpathExpr, nsMap, val, ref bValueIsFragment);
				}
				else
				{
					bOriginalFragmentValue = (bValueIsFragment = false);
					DotNetXmlImpl.Update(xmlDocument, xpathExpr, nsMap, val, ref bValueIsFragment);
				}
				m_xmlTypeImpl.Invalidate(bOriginalFragmentValue, bValueIsFragment, ref m_bGotRootElement);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, "OracleXmlType::Update(xpathexpr, nsmap, stringval)");
				}
			}
		}

		public void Update(string xpathExpr, XmlNamespaceManager nsMgr, string val)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, "OracleXmlType::Update(xpathexpr, nsMgr, xmltypeval)");
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (string.IsNullOrEmpty(xpathExpr))
				{
					throw new ArgumentNullException("xpathExpr");
				}
				if (val == null)
				{
					throw new ArgumentNullException("val");
				}
				XmlDocument xmlDocument = m_xmlTypeImpl.GetXmlDocument(bInternalUse: true, bThrowException: false);
				bool bOriginalFragmentValue;
				bool bValueIsFragment;
				if (m_xmlTypeImpl.m_xmlDocFragmentInternal != null)
				{
					bOriginalFragmentValue = (bValueIsFragment = true);
					DotNetXmlImpl.Update(xmlDocument, "/" + xpathExpr, nsMgr, val, ref bValueIsFragment);
				}
				else
				{
					bOriginalFragmentValue = (bValueIsFragment = false);
					DotNetXmlImpl.Update(xmlDocument, xpathExpr, nsMgr, val, ref bValueIsFragment);
				}
				m_xmlTypeImpl.Invalidate(bOriginalFragmentValue, bValueIsFragment, ref m_bGotRootElement);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Update, "OracleXmlType::Update(xpathexpr, nsMgr, xmltypeval)");
				}
			}
		}

		public bool Validate(string schemaUrl)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Validate);
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (string.IsNullOrEmpty(schemaUrl))
				{
					throw new ArgumentNullException("schemaUrl");
				}
				if (m_bIsEmpty)
				{
					return false;
				}
				bool result = false;
				XmlSchemaPool xmlSchemaPool = null;
				OracleClob schemaInfo = null;
				string text = null;
				byte[] schemaId = null;
				if (m_connection.m_oracleConnectionImpl != null && m_connection.m_oracleConnectionImpl.m_pm != null && m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPool != null)
				{
					lock (m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPoolLock)
					{
						if (m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPool.ContainsKey(m_connection.m_oracleConnectionImpl.ServiceName))
						{
							xmlSchemaPool = m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPool[m_connection.m_oracleConnectionImpl.ServiceName];
						}
						else
						{
							xmlSchemaPool = new XmlSchemaPool(200);
							m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPool[m_connection.m_oracleConnectionImpl.ServiceName] = xmlSchemaPool;
						}
					}
				}
				if (xmlSchemaPool != null && xmlSchemaPool.Contains(schemaUrl) && xmlSchemaPool[schemaUrl] != null)
				{
					text = xmlSchemaPool[schemaUrl].schemaInfo;
				}
				else
				{
					if (m_command == null)
					{
						m_command = new OracleCommand("", m_connection);
					}
					OraXmlImpl.GetSchema(m_command, this, schemaUrl, out schemaInfo, out schemaId);
					if (schemaInfo != null && !schemaInfo.IsNull && xmlSchemaPool != null)
					{
						text = schemaInfo.Value;
						xmlSchemaPool[schemaId] = new CachedSchemaWithUrl(schemaUrl, text);
						xmlSchemaPool[schemaUrl] = new CachedSchemaWithId(schemaId, text);
					}
				}
				if (text != null)
				{
					DotNetXmlValidator dotNetXmlValidator = new DotNetXmlValidator(text);
					XmlReader xmlReader = m_xmlTypeImpl.GetXmlReader(dotNetXmlValidator.m_readerSettings);
					result = dotNetXmlValidator.Validate(xmlReader);
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Validate, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Validate);
				}
			}
		}

		internal void Dispose(bool disposing)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Dispose);
			}
			if (m_bClosed)
			{
				return;
			}
			lock (lockXmlType)
			{
				try
				{
					if (!m_bNotNull)
					{
						return;
					}
					if (!m_bClosed)
					{
						Close();
					}
					if (disposing)
					{
						if (m_command != null)
						{
							m_command.Dispose();
						}
						m_command = null;
						m_connection = null;
					}
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Dispose, ex);
				}
				finally
				{
					if (ProviderConfig.m_bTraceLevelPrivate)
					{
						Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Dispose);
					}
				}
			}
		}

		internal void Close()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Close);
			}
			if (m_bClosed)
			{
				return;
			}
			lock (lockXmlType)
			{
				try
				{
					if (m_bNotNull && !m_bClosed)
					{
						m_xmlTypeImpl.Dispose();
						if (m_schemaClob != null)
						{
							m_schemaClob.Dispose();
							m_schemaClob = null;
						}
						m_bClosed = true;
					}
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Close, ex);
				}
				finally
				{
					if (m_connection != null && m_connection.m_oracleConnectionImpl != null)
					{
						m_connection.m_oracleConnectionImpl.DeregisterForConnectionClose(this);
					}
					if (ProviderConfig.m_bTraceLevelPrivate)
					{
						Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.Close);
					}
				}
			}
		}

		internal void Set(OracleConnection conn, OraXmlTypeHeader xmlTypeHeader, OraXmlTypeData xmlTypeData)
		{
			if (m_bNotNull)
			{
				m_xmlTypeImpl.Dispose();
				if (m_schemaClob != null)
				{
					m_schemaClob.Dispose();
				}
				m_bPopluateSchema = false;
				m_bIsSchemaBased = false;
				m_schemaURL = string.Empty;
				m_schemaClob = null;
				m_bGotRootElement = false;
				m_rootElement = string.Empty;
				m_xmlTypeImpl.Set(conn.m_oracleConnectionImpl, xmlTypeHeader, xmlTypeData);
				m_xmlTypeImpl.Initialize(conn);
			}
		}

		internal void ConnectionClose()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ConnectionClose);
			}
			try
			{
				if (!m_bClosed)
				{
					Close();
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ConnectionClose, ex);
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.ConnectionClose);
				}
			}
		}

		internal bool GetSchemaInfo(bool bGetSchemaValue, out string xmlSchemaValue)
		{
			xmlSchemaValue = null;
			if (m_bPopluateSchema && !bGetSchemaValue)
			{
				return m_bIsSchemaBased;
			}
			try
			{
				string schemaURL = null;
				byte[] schemaID = null;
				m_xmlTypeImpl.GetXmlSchemaProp(out schemaURL, out schemaID, out var bHasTargetNamespace);
				if (schemaID != null || !string.IsNullOrEmpty(schemaURL))
				{
					schemaURL.Trim();
					if (bHasTargetNamespace)
					{
						string[] array = schemaURL.Split(' ', '\n', '\t', '\r');
						if (array.Length >= 2)
						{
							schemaURL = array[1];
						}
					}
				}
				if (schemaID != null || !string.IsNullOrEmpty(schemaURL))
				{
					m_bIsSchemaBased = true;
				}
				else
				{
					m_bIsSchemaBased = false;
				}
				if (m_bIsSchemaBased)
				{
					XmlSchemaPool xmlSchemaPool = null;
					if (m_connection.m_oracleConnectionImpl != null && m_connection.m_oracleConnectionImpl.m_pm != null && m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPool != null)
					{
						lock (m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPoolLock)
						{
							if (m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPool.ContainsKey(m_connection.m_oracleConnectionImpl.ServiceName))
							{
								xmlSchemaPool = m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPool[m_connection.m_oracleConnectionImpl.ServiceName];
							}
							else
							{
								xmlSchemaPool = new XmlSchemaPool(200);
								m_connection.m_oracleConnectionImpl.m_pm.m_dictXmlSchemaPool[m_connection.m_oracleConnectionImpl.ServiceName] = xmlSchemaPool;
							}
						}
					}
					if (schemaID != null && xmlSchemaPool != null && xmlSchemaPool.Contains(schemaID) && xmlSchemaPool[schemaID] != null)
					{
						CachedSchemaWithUrl cachedSchemaWithUrl = xmlSchemaPool[schemaID];
						xmlSchemaValue = cachedSchemaWithUrl.schemaInfo;
						m_schemaURL = cachedSchemaWithUrl.schemaUrl;
						m_schemaID = schemaID;
					}
					else if (schemaURL != null && xmlSchemaPool != null && xmlSchemaPool.Contains(schemaURL) && xmlSchemaPool[schemaURL] != null)
					{
						CachedSchemaWithId cachedSchemaWithId = xmlSchemaPool[schemaURL];
						xmlSchemaValue = cachedSchemaWithId.schemaInfo;
						m_schemaURL = schemaURL;
						m_schemaID = cachedSchemaWithId.schemaId;
					}
					else
					{
						if (m_schemaClob == null)
						{
							if (m_command == null)
							{
								m_command = new OracleCommand("", m_connection);
							}
							if (schemaID != null)
							{
								OraXmlImpl.GetSchema(m_command, this, schemaID, out m_schemaClob, out schemaURL);
							}
							else
							{
								OraXmlImpl.GetSchema(m_command, this, schemaURL, out m_schemaClob, out schemaID);
							}
						}
						if (m_schemaClob != null && !m_schemaClob.IsNull && xmlSchemaPool != null)
						{
							if (bGetSchemaValue)
							{
								xmlSchemaValue = m_schemaClob.Value;
								xmlSchemaPool[schemaID] = new CachedSchemaWithUrl(schemaURL, xmlSchemaValue);
								xmlSchemaPool[schemaURL] = new CachedSchemaWithId(schemaID, xmlSchemaValue);
							}
							else
							{
								xmlSchemaPool[schemaID] = null;
								xmlSchemaPool[schemaURL] = null;
							}
							m_schemaURL = schemaURL;
							m_schemaID = schemaID;
						}
					}
				}
				m_bPopluateSchema = true;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleXmlType, OracleTraceFuncName.GetSchemaInfo, ex);
			}
			finally
			{
				m_bPopluateSchema = true;
			}
			return m_bIsSchemaBased;
		}
	}
}
